import os

path = "D:/BaiduNetdiskDownload/电子商务与电子政务实验数据/搜狗搜索日志/SogouQ/SogouQ/"
path_origin = "D:/BaiduNetdiskDownload/电子商务与电子政务实验数据/搜狗搜索日志/SogouQ/data_origin/"
path_after_process = "D:/BaiduNetdiskDownload/电子商务与电子政务实验数据/搜狗搜索日志/SogouQ/data_after_process/"


def log_to_file():
    file_list = os.listdir(path_origin)
    for file in file_list:
        data_after_process = open(path_after_process + file, 'a', encoding="utf-8")
        datas_file_origin = open(path_origin + file, encoding="ANSI")
        data_origin_lines = datas_file_origin.readlines()
        for data_origin_line in data_origin_lines:
            data_to_write = data_origin_line.split('\t')[1]
            data_to_write_new = data_to_write.replace('[', '').replace(']', '')
            data_after_process.write(data_to_write_new)
            data_after_process.write('\n')


def change_file_name():
    os.chdir(path_after_process)
    file_list = os.listdir(path_after_process)
    for file in file_list:
        file_new = file.replace("filter", "txt")
        os.rename(file, file_new)


if __name__ == '__main__':
    # log_to_file()
    change_file_name()
